package com.cbtx.module_sp.ui.vm

import android.app.Application
import android.content.Intent
import androidx.lifecycle.MutableLiveData
import com.cbtx.module.base.http.HttpBaseBean
import com.cbtx.module.base.http.HttpManager
import com.cbtx.module.base.http.MyRequestCallBack
import com.cbtx.module.base.vm.BaseVM
import com.cbtx.module.common.bean.BannerBean
import com.cbtx.module.common.http.HttpUrlManager
import com.txcb.lib.base.utils.FileUtils
import com.txcb.lib.base.utils.LogUtil
import com.txcb.lib.base.utils.MD5Util
import com.txcb.lib.base.utils.SharedPreferencesUtils
import java.io.File
import java.io.Serializable

class AdvActivityVM(application: Application) : BaseVM(application) {

    val bannerItemList: MutableLiveData<MutableList<BannerBean.BannerItem>> = MutableLiveData()

    fun getIntent(intent: Intent) {
        val bannerData = intent.getSerializableExtra("bannerItemList") as Serializable

        val bannerItemList2: MutableList<BannerBean.BannerItem> =
            bannerData as ArrayList<BannerBean.BannerItem>

        checkFile(bannerItemList2)
    }

    fun checkFile(bannerItemList2: MutableList<BannerBean.BannerItem>) {

       val bannerItemList3: MutableList<BannerBean.BannerItem> = ArrayList()
        for (bannerItem in bannerItemList2) {

            if (bannerItem == null){
                continue
            }

            val downloadUrl = bannerItem.bannerImgurl
            val indext = downloadUrl.lastIndexOf("/") + 1
            val fileName = downloadUrl.substring(indext)
            val filePath: String = FileUtils.getDownloadDir()

            val allPath = "$filePath/$fileName"

            val videoFile = File(allPath)
            if (videoFile.exists()){

                bannerItemList3.add(bannerItem)
            }
        }

        bannerItemList.value = bannerItemList3
    }



}